﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Bus.Bll;
using Bus.Model;

public partial class admin_user_userlist : System.Web.UI.Page
{
    protected tb_user userbll = new tb_user();
    protected tb_log logbll = new tb_log();
    protected LogModel lm = null;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            this.ProviderData();
        }
    }
    private void ProviderData()
    {
        try
        {

            userlist.PageSize = 10;
            userlist.RecordCount = userbll.GetRecordCount("");
            userrep.DataSource = userbll.GetListByPage("", "uid desc", (userlist.CurrentPageIndex - 1) * userlist.PageSize, userlist.PageSize);
            userrep.DataBind();
        }
        catch (Exception e) { }
    }
    public string ToLeavl(object v)
    {
        int vl = int.Parse(v.ToString ().Trim ());
        string temp = string.Empty;
        if(vl==0)
            temp= "经理";
        if (vl == 1)
            temp = "业务员";
        if (vl == 2)
            temp = "出纳员";
        if (vl == 4)
            temp = "司机";
        return temp;
    }
    protected void userlist_PageChanged(object sender, EventArgs e)
    {
        ProviderData();
    }
    protected void LinkButton1_click(object sender, EventArgs e)
    {
        LinkButton lbt = sender as LinkButton;
        int cid = int.Parse(lbt.CommandArgument);
        if (userbll.Delete(cid))
        {
            lm = new LogModel();
            lm.userid = int.Parse(Session["userid"].ToString());
            lm.op = "删除";
            lm.memo = "删除一个用户";
            lm.opdate = DateTime.Now;
            logbll.Add(lm);
            Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('删除成功！');</script>");
            ProviderData();
        }
        else
            Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('删除失败！');</script>");
    }
}
